USE [Smart]
GO

/****** Object:  Table [dbo].[ExerciseCategory]    Script Date: 06/01/2012 23:29:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[ExerciseCategory](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Category] [varchar] (50) NOT NULL,
 CONSTRAINT [PK_ExerciseCategory] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

CREATE TABLE [dbo].[Exercise](
	[ExerciseId] [int] IDENTITY(1,1) NOT NULL,
	[CategoryId] [int] NOT NULL,
	[ExerciseName] [varchar](50) NOT NULL,
	[CaloriesPerHour] [int] NOT NULL,
 CONSTRAINT [PK_exercise] PRIMARY KEY CLUSTERED 
(
	[ExerciseId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Exercise]  WITH CHECK ADD  CONSTRAINT [FK_exercise_ExerciseCategory1] FOREIGN KEY([CategoryId])
REFERENCES [dbo].[ExerciseCategory] ([Id])
GO

ALTER TABLE [dbo].[Exercise] CHECK CONSTRAINT [FK_exercise_ExerciseCategory1]
GO


CREATE TABLE [dbo].[ExerciseLog](
	[LogId] [int] IDENTITY(1,1) NOT NULL,
	[UserId] [int] NOT NULL,
	[ExerciseId] [int] NOT NULL,
	[ExerciseDate] [date] NOT NULL,
	[Duration] [int] NOT NULL,
	[BurnedCals] [int] NULL,
 CONSTRAINT [PK_ExerciseLog] PRIMARY KEY CLUSTERED 
(
	[LogId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[ExerciseLog]  WITH CHECK ADD  CONSTRAINT [FK_ExerciseLog_exercise] FOREIGN KEY([ExerciseId])
REFERENCES [dbo].[Exercise] ([ExerciseId])
GO

ALTER TABLE [dbo].[ExerciseLog] CHECK CONSTRAINT [FK_ExerciseLog_exercise]
GO

ALTER TABLE [dbo].[ExerciseLog]  WITH CHECK ADD  CONSTRAINT [FK_ExerciseLog_User] FOREIGN KEY([UserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[ExerciseLog] CHECK CONSTRAINT [FK_ExerciseLog_User]
GO

ALTER TABLE [dbo].[ExerciseLog] ADD  CONSTRAINT [DF__ExerciseL__Exerc__07F6335A]  DEFAULT (getdate()) FOR [ExerciseDate]
GO


